//
//  FocusAndFansTableViewCell2.m
//  CYWFrame
//
//  Created by Macx on 2017/8/29.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "FocusAndFansTableViewCell2.h"

#import "User.h"
#import <Masonry.h>
#import "PushPerHome.h"

@implementation FocusAndFansTableViewCell2

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.headPic.frame = CGRectMake(10, 10, SW(8), SW(8));
    self.headPic.layer.cornerRadius = self.headPic.width/2;
    self.headPic.layer.masksToBounds = YES;
    
    self.levelImg.frame = CGRectMake(10+SW(8)-SW(8)/3, 10+SW(8)-SW(8)/3, SW(8)/3, SW(8)/3);
    
    
    CGSize nickNameSize = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(14)];
    //    CGSize signSize = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(12)];
    
    self.nickName.font = kUHSystemFontWithSize(14);
    self.nickName.frame = CGRectMake(20+self.headPic.width, 10, SCREEN_WIDTH-30-self.headPic.width, nickNameSize.height);
    
    [self.genderImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(10);
        make.left.mas_equalTo(self.nickName.mas_right).offset(2);
        make.size.mas_equalTo(CGSizeMake(nickNameSize.height, nickNameSize.height));
    }];
    
    self.level.titleLabel.font = kUHSystemFontWithSize(12);
    [self.level mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(10);
        make.left.mas_equalTo(self.genderImg.mas_right).offset(2);
    }];
    self.level.userInteractionEnabled = NO;
    [self.level setBackgroundImage:[UIImage imageNamed:@"level_bg"] forState:UIControlStateNormal];
    [self.level setImage:[[UIImage imageNamed:@"level_star"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.level setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    self.sign.font = kUHSystemFontWithSize(12);
    
    self.optionsBtn.titleLabel.font = kUHSystemFontWithSize(13);
    [self.optionsBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    CGSize size3 = [LZCTools textSizeWithText:@"未关注" font:kUHSystemFontWithSize(13)];
    CGFloat focusWidth = self.headPic.height/2+5+size3.width;
    self.optionsBtn.frame = CGRectMake(SCREEN_WIDTH-10-focusWidth, self.headPic.height/4+10, focusWidth, self.headPic.height/2);
}


- (void)setModel:(User *)model {
    
    if (_model != model) {
        _model = model;
        
        [self.headPic sd_setImageWithURL:[NSURL URLWithString:model.face] placeholderImage:IMAGE(@"placeHolder")];
        
        NSDictionary *user = @{@"is_blocked":[NSString stringWithFormat:@"%ld", model.is_blocked],
                               @"user_id":[NSString stringWithFormat:@"%ld", model.user_id],
                               @"face":model.face,
                               @"nickname":model.nickname,
                               @"role":[NSString stringWithFormat:@"%ld", model.role],
                               @"sex":[NSString stringWithFormat:@"%ld", model.sex],
                               @"is_like":[NSString stringWithFormat:@"%ld", model.is_like],
                               @"level":model.level,
                               @"pro_intro":model.pro_intro};
        
        [self.headPic addActionWithblock:^{
            
            [PushPerHome pushPerHomeWithUserInfo:user];
        }];
        
        self.nickName.text = model.nickname;
        if (self.nickName.text.length > 8) {
            self.nickName.text = [self.nickName.text substringToIndex:8];
        }
        //        self.nickName.text = @"xxx";
        
        self.sign.text = model.intro;
        
        CGSize nickNameSize = [LZCTools textSizeWithText:self.nickName.text font:kUHSystemFontWithSize(14)];
        self.nickName.frame = CGRectMake(20+self.headPic.width, 10, nickNameSize.width, nickNameSize.height);
        
        if (model.sex == 0) {
            self.genderImg.image = [UIImage imageNamed:@"per_sex"];
        }
        else if (model.sex == 1) {
            self.genderImg.image = IMAGE(@"sex_boy");
        }
        else
            self.genderImg.image = IMAGE(@"sex_girl");
        
        if ([[model valueForKey:@"is_like"] intValue] == 1) {
            [self.optionsBtn setBackgroundImage:IMAGE(@"btn_concerned_bg") forState:UIControlStateNormal];
            [self.optionsBtn setImage:[IMAGE(@"btn_ed_concern") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            [self.optionsBtn setTitle:@"已关注" forState:UIControlStateNormal];
        }
        else {
            [self.optionsBtn setBackgroundImage:IMAGE(@"btn_unconcern_bg") forState:UIControlStateNormal];
            [self.optionsBtn setImage:[IMAGE(@"btn_un_concern") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            [self.optionsBtn setTitle:@"  关注" forState:UIControlStateNormal];
        }
        
        [self.level setTitle:[NSString stringWithFormat:@" %@", [model valueForKey:@"level"]] forState:UIControlStateNormal];
        CGSize vipSize = [LZCTools textSizeWithText:self.level.titleLabel.text font:kUHSystemFontWithSize(12)];
        self.level.size = CGSizeMake(nickNameSize.height+vipSize.width+5, nickNameSize.height);
        
        self.sign.frame = CGRectMake(20+self.headPic.width, 10+self.headPic.width-vipSize.height, SCREEN_WIDTH-(self.optionsBtn.width+35+self.headPic.width), vipSize.height);
        
        if (model.role == 1) {
            self.levelImg.image = IMAGE(@"");
        }
        else if (model.role == 3 || model.role == 4 || model.role == 6) {
            self.levelImg.image = IMAGE(@"icon_add_v");
        }
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
